require("../../assets/css/index.less")
require("./course.less")

const { getEle, publicFooter, publicHeader, isLogin, ready } = require("../../utils/dom")
const { get, BASE_URL } = require("../../utils/https")
publicFooter('run')
publicHeader('course')
isLogin()

ready(()=>{
    get("/api/train/courseList",(res)=>{
        let{errno,data}=res
        console.log(data)
        let newClass = data.shift()
        // getEle("#imgurl").src = BASE_URL + newClass.imgUrl
        getEle("#name").textContent = newClass.name
        getEle("#desc").textContent = newClass.desc
        getEle(".new-class").dataset.cid = newClass.courseId

        let course = data
        let arr = course.map(function (v) {
            return `
                <li data-cid="${v.courseId}" class="over cfff rel">
                <img src="${BASE_URL + v.imgurl}" alt="">
                <p class="abs f20">${v.name}</p>
                <span class="abs f14">${v.desc}</span>
                </li>
                `
        }).join("")
        getEle("#curriculum").innerHTML = arr
    })

    // //获取最新课程的自定义类名值
// document.querySelector(".new-class").addEventListener("click", function () {
//     //点击获取值
//     let cid = this.dataset.cid
//     //存入会话
//     sessionStorage.setItem("cid", cid)
//     //点击跳转
//     location.href = "./cit.html"
// })

// //获取课程的自定义类名值
// document.querySelector("#curriculum").addEventListener("click", function (event) {
//     console.log(event.target.nodeName)
//     if (event.target.nodeName === "IMG" || event.target.nodeName === "SPAN" || event.target.nodeName === "P") {
//         //点击获取值
//         let cid = event.target.closest("li").dataset.cid
//         //存入会话
//         sessionStorage.setItem("cid", cid)
//         //点击跳转
//         location.href = "./cit.html"
//     }
// })
})

